OpenBuildings GenerativeComponents Help

ref and out Values

Any function, in any context, may have ref and/or out arguments. They are just additional tools to help a programmer express their ideas in code.

Any individual argument may be ref, out, or neither:

  • An argument that's neither ref nor out is purely an input to the function.
  • An argument that's out is purely an output from the function.
  • An argument that's ref is both an input and output.

Here is a script transaction that demonstrates the three cases:

transaction 1 script 'New script transaction'
{
    	void f(int x, ref int y, out int z)
    	{
    	Print(); 
             PrintFormat("       Just entered f: x = {0}, y = {1}, z = {2}.", x, y, z);
             x += 10;
             y += 10;
             y += 10;
             Print();
             PrintFormat("       About to return from f: x = {0}, y = {1}, z = {2}.", x, y, z);
             }
             int a = 1, b = 2, c = 3;
             Print();
             PrintFormat("Before calling f: a = {0}, b = {1}, c = {2}", a, b, c);
             f(a, ref b, out c);
            Print();
            PrintFormat("After calling f: a = {0}, b = {1}, c = {2}", a, b, c); 
}

When this transaction is run, it prints the following output to the script console:

Before calling f: a = 1, b = 2, c = 3
	Just entered f: x = 1, y = 2, z = 0.
	About to return from f: x = 11, y = 12, z = 10.
After calling f: a = 1, b = 12, c = 10

To open the console window, you must navigate through the ribbon and select the (Script Console ).